home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#42 (Mar 89)
/
string width
Wrap
Text File
|
1989-02-14
|
2KB
|
79 lines
{$R-}
(*
strWidth -- a sample HyperCard external command
that gets the width of a string.
Written in MPW Pascal.
Written by Fred Stauder
MacTutor 1989
pascal :Sources:XCMD:strWidth.p
link -o AJS:test -rt XCMD=7002 -sn ∂
Main=strWidth :Sources:XCMD:strWidth.p.o ∂
{MPW}PLibraries:PasLib.o -m ENTRYPOINT
*)
{$S strWidth } { Segment name must be same as command name. }
UNIT Fred_Stauder;
INTERFACE
USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PasLibIntf, HyperXCmd;
PROCEDURE ENTRYPOINT(paramPtr:XCmdPtr);
IMPLEMENTATION
TYPE Str31 = String[31];
PROCEDURE strWidth(paramPtr:XCmdPtr); FORWARD;
PROCEDURE ENTRYPOINT(paramPtr:XCmdPtr);
BEGIN
strWidth(paramPtr);
END;
PROCEDURE strWidth(paramPtr:XCmdPtr);
VAR
tempStr: Str255;
tempInt: Integer;
{$I XCmdGlue.inc } {includes the glue routines}
PROCEDURE Error(errStr:Str255); {return an error message}
BEGIN
paramPtr^.returnValue := PasToZero(errStr);
{put error into 'the result'}
EXIT(strWidth); {leave the XCMD}
END; {Error}
PROCEDURE ParamCheck;
CONST paramCount: Integer;
VAR params: Integer;
BEGIN
params := paramPtr^.paramCount;
IF (params <> paramCount)
THEN Error('strWidth "String" or Container');
END; {ParamCheck}
BEGIN {Main}
CheckParamCount;
ZeroToPas(paramPtr^.params[1]^,tempStr);
{get the first Param}
tempInt := StringWidth(tempStr) ; {get the width}
tempStr := NumToStr(tempInt);
paramPtr^.returnValue := PasToZero(tempStr);
END; {Main}
END. {strWidth}